<?php
	include_once("adb.php");
	
	class users extends adb{
		function users(){
			adb::adb();
		}
		/**
		*query all vaccines in the table and store the dataset in $this->result	
		*@return if successful true else false
		*/
		
		function get_all_users(){
			$query="select * from users";
			return $this->query($query);
		}
		
		function login($user_name,$password){
			$query = "select user_name,password from users where user_name='$user_name' and password=MD5('$password')";
			if(!$this->query($query)) {
			return false;
			}
			else{
			$num=$this->get_num_rows();

				if ($num == 0){
				return false;
				}

				else{
				return true;
				}
			}
		}
		function add_users($firstname,$lastname,$user_name,$password,$position,$status,$date_created,$phone_number){
			//write the SQL query and call $this->query()
			$query="insert into users set firstname='$firstname',lastname='$lastname',user_name='$user_name',password='$password', 
			position=$position,status=$status,date_created=now(),phone_number=$phone_number";
			return $this->query($query);
		}
		/**
		*updates the record identified by id 
		*/
		function update_users($id,$firstname,$lastname,$user_name,$password,$position,$status,$date_created,$phone_number){
		 	//write the SQL query and call $this->query()
			$query="update users set firstname='$firstname',lastname='$lastname',user_name='$user_name',password='$password', 
			position=$position,status=$status,date_created=now(),phone_number=$phone_number where id=$id";
			return $this->query($query);
		 }
		/**
		 *deletes the record identified by id 
		 */
		 function delete_user($id){
			//write the SQL query and call $this->query()
		 	$query="delete from users where id=$id";
		 	return $this->query($query);
		 }
		 function search($firstname){
		 	$query="select * from users where firstname like '%$firstname%'";
		 	return $this->query($query);
		 }
		 function get_user($id){
		 	$query="select * from users where id=$id";
		 	return $this->query($query);
		 }
		
	}
	
	//call methods here to test
	// $obj=new vaccines();
	// if (!$obj->get_all_vaccines()){
	// 	echo "error";
	// }

	// $row=$obj->fetch();
	// while($row){
	// 	print_r($row);
	// $row=$obj->fetch();
		
	// }
?>